<script type="text/javascript">
    var tenantCode = "";
    var keyId = (getUrlParam("keyId", url));
    showLoading();
    fy_api.ajax({
        url: "smsSetting/getTenantCodeForSelectBox.do?_t=" + new Date().getTime(),
        type: "POST",
        data: "",
        success: function (data) {
            if (data.success) {
                tenantCode = data.message;
            }
        }
    });
    $(function () {
        $("#btnSave").click(function () {

            if (!checkForm(document.getElementById("saveForm"))) {
                return;
            }

            $("#btnSave").blur();
            showLoading();
            fy_api.ajaxSubmit($("#saveForm"),{
                success: function (data) {
                    hideLoading();
                    if (!data.success) {
                        alert(data.message);
                    } else {
                       alert("保存成功！");
                        parent.grid_get("grid").datagrid("load");
                        turnBack();
                    }
                }
            });
        });
        if(keyId != ""){
            //编辑
            $("#code").attr("disabled",true);
            fy_api.load_template({
                controller: $("#saveForm").attr("templateParam", "keyId=" + keyId), loading: true, initValue: true, loaded: loaded
            });
        }else{
            //添加
            $("#divEdit").remove();
            fy_api.load_template({
                controller: $("#saveForm").attr("action","smsSetting/save.do"), loading: true, initValue: true, loaded: loaded
            });
        }
    });

    function loaded(){
        $("#tenantCode").val(tenantCode);
        var options = $("#tenantCode").val().split(",");
        for(var i=0;i<options.length;i++){
            if(options[i] == $("#tenantCodeHid").val()){
                $("#code").append("<option selected value="+options[i]+">"+options[i]+"</option>");
            }else{
                $("#code").append("<option value="+options[i]+">"+options[i]+"</option>");
            }

        }
    }
    function turnBack() {
        parent.j_closeWin();
    }
</script>
<form action="smsSetting/update.do" method="post" id="saveForm" templateUrl="smsSetting/get.do">
    <div id="divEdit">
        <input type="hidden" name="id" value="${id}"/>
        <input type="hidden" id="tenantCodeHid" name="tenantCodeHid" value="${code}"/>
    </div>
    <div >
        <input type="hidden" id="tenantCode" name="tenantCode" value=""/>
    </div>
    <div class="div-item" style="width: 100%;">
        <div class="div-label"><strong>基本信息设置</strong></div>
    </div>
    <div class="div-item">
        <div class="div-label"><span class="nullTip">*</span>租户唯一标识：</div>
        <select name="code" id="code" value="${code}">

        </select>
    </div>
    <div class="div-item" style="width: 100%;">
    </div>
    <div class="div-item">
        <div class="div-label"><span class="nullTip">*</span>使用状态：</div>
        <select name="useStatus" id="useStatus" value="${useStatus}">
            <option value="Y">使用中</option>
            <option value="N">已停用</option>
        </select>
    </div>
    <div class="div-item">
        <div class="div-label"><span class="nullTip">*</span>默认短信通道：</div>
        <select name="defaultSmsSupplierNo" id="defaultSmsSupplierNo" value="${defaultSmsSupplierNo}">
            <option value="1">即时通</option>
            <option value="2">EMS</option>
            <option value="3">微网通联</option>
            <option value="5">上海助通</option>
        </select>
    </div>
    <div class="div-item">
        <div class="div-label"><span class="nullTip">*</span>默认语音短信通道：</div>
        <select name="defaultVoiceSupplierNo" id="defaultVoiceSupplierNo" value="${defaultVoiceSupplierNo}">
            <option value="1">即时通</option>
        </select>
    </div>
    <div class="div-item" style="width:550px;">
        <div class="div-label">备注：</div>
        <input type="text" name="remark" id="remark" value="${remark}" maxlength="100"/>
    </div>
</form>
<div class="form-buttons">
    <a id="btnSave" class="easyui-linkbutton" iconCls="icon-save">保存</a>
    <a id="btnBack" class="easyui-linkbutton c2" iconCls="icon-undo" onClick="turnBack();">返回</a>
</div>